﻿Imports VBParser
Imports NotBasic.Compiler.Semantic

Namespace Compiler
    ''' <summary>
    ''' Process all Semantic errors, generate comment syntax tree
    ''' </summary>
    Public Class TypeDeclarationAnalysis

        Private m_typeEnv As Environment(Of TypeDescription)
        Protected ReadOnly Property TypeEnvironment() As Environment(Of TypeDescription)
            Get
                Return m_typeEnv
            End Get
        End Property

        Private m_errorList As List(Of SemanticError)

        Private m_compileUnit As CompileUnitDescription
        Public Function GetCompileUnit() As CompileUnitDescription
            Return m_compileUnit
        End Function

        Public Sub TranslateImports(ByVal decl As ImportsDeclaration)

        End Sub

        'Public Function TranslateNamespace(ByVal decl As NamespaceDeclaration) As NamespaceDescription

        'End Function

        'Public Function TranslateClass(ByVal parent As NameContainer, ByVal decl As ClassDeclaration) As ClassDescription
        '    'check if the class has been already declared
        '    Dim name As Symbol = Symbol.Get(decl.Name.Name)
        '    Dim typeParameters As TypeParameterCollection = decl.TypeParameters
        '    Dim typeParamCount As Integer = 0

        '    If typeParameters IsNot Nothing Then typeParamCount = typeParameters.Count

        '    Dim binder As Binder = New TypeDeclBinder(name, typeParamCount)
        '    Dim result As TypeDescription = TypeEnvironment.Search(binder)

        '    If result IsNot Nothing Then
        '        'already declared
        '        m_errorList.Add(New SemanticError(SemanticErrorType.TypeDefinitionConflict, decl.Span))
        '        Return Nothing
        '    End If

        '    'generate type description
        '    result = New ClassDescription(parent)
        '    result.Name = name

        '    'add to environment
        '    TypeEnvironment.CurrentTable.Enter(binder, result)

        '    'add to global environment if modifier is Public 

        '    'TypeEnvironment.PushQualifierSection( _
        '    '    New QualifierSection() With {.Name = name, .Connector = QualifierSection.NestedTypeConnector})

        '    TypeEnvironment.BeginScope()
        '    Try
        '        'analysis type parameters
        '        If typeParamCount > 0 Then
        '            'define typeParameters
        '            For Each tp As TypeParameter In typeParameters
        '                Dim tpName As Symbol = Symbol.Get(tp.TypeName.Name)
        '                Dim tpBinder As Binder = New TypeDeclBinder(tpName)

        '                Dim tpDesc As TypeDescription = TypeEnvironment.Search(tpBinder)

        '                If tpDesc IsNot Nothing Then
        '                    m_errorList.Add(New SemanticError(SemanticErrorType.TypeParameterRedefined, tp.Span))
        '                    Continue For
        '                End If

        '                tpDesc = New TypeParameterDescription(result) With {.Name = tpName, .HostType = result, .SyntaxNode = tp}
        '                'add to environment
        '                TypeEnvironment.CurrentTable.Enter(binder, result)
        '            Next
        '        End If

        '        'analysis nested types
        '        For Each subDecl As Declaration In decl.Declarations
        '            Select Case subDecl.Type
        '                Case TreeType.ClassDeclaration

        '            End Select
        '        Next
        '    Finally
        '        TypeEnvironment.EndScope()
        '        'TypeEnvironment.PopQualifierSection()
        '    End Try
        'End Function

        'Public Function TranslateStruct(ByVal decl As StructureDeclaration) As StructureDescription

        'End Function

        'Public Function TranslateInterface(ByVal decl As InterfaceDeclaration) As InterfaceDescription

        'End Function

        'Public Function TranslateDelegate(ByVal decl As DelegateDeclaration) As DelegateDescription

        'End Function

        'Public Function TranslateEnum(ByVal decl As EnumDeclaration) As EnumDescription

        'End Function

        'Public Function TranslateModule(ByVal decl As ModuleDeclaration) As ClassDescription

        'End Function
    End Class

End Namespace